# Copyright (c) 2008-2009 Mikhail Chernov 
#
# This file is part of dcExplorer.
#
# dcExplorer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# dcExplorer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dcExplorer.  If not, see <http://www.gnu.org/licenses/>.

package dcExplorer::wxui::widget::Stats;
use strict;
use Wx;
use base 'Wx::Panel';
use Wx qw(wxHORIZONTAL wxVERTICAL wxEXPAND wxALL);
use Wx qw(wxALIGN_LEFT wxALIGN_CENTRE wxALIGN_RIGHT wxST_NO_AUTORESIZE);

sub new
{
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $parent = shift;
	my $id = shift;
	my $self = $class->SUPER::new($parent, $id, [-1, -1], [-1, 200]); 
	$self->SetBackgroundColour(Wx::Colour->new(0, 0, 0));
	my $empire = shift;
	my $color = Wx::Colour->new(192, 192, 192);
	$self->{Label_player} = Wx::StaticText->new($self, -1, "Player", [-1, -1], [-1, -1], wxALIGN_LEFT | wxST_NO_AUTORESIZE);
	$self->{Label_player}->SetForegroundColour($color);
	$self->{Label_turn} = Wx::StaticText->new($self, -1, "Turn", [-1, -1], [-1, -1], wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
	$self->{Label_turn}->SetForegroundColour($color);
	$self->{Label_time} = Wx::StaticText->new($self, -1, "Time", [-1, -1], [-1, -1], wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
	$self->{Label_time}->SetForegroundColour($color);
	$self->{Label_m} = Wx::StaticText->new($self, -1, "M", [-1, -1], [-1, -1], wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
	$self->{Label_m}->SetForegroundColour($color);
	$self->{Label_s} = Wx::StaticText->new($self, -1, "S", [-1, -1], [-1, -1], wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
	$self->{Label_s}->SetForegroundColour($color);
	$self->{Label_c} = Wx::StaticText->new($self, -1, "C", [-1, -1], [-1, -1], wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
	$self->{Label_c}->SetForegroundColour(Wx::Colour->new(255, 255, 0));
	$self->setEmpire($empire);
	$self->{Sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
	$self->{Sizer}->Add($self->{Label_player}, 1, wxEXPAND | wxALL, 1);
	$self->{Sizer}->Add($self->{Label_turn}, 0, wxEXPAND | wxALL, 1);
	$self->{Sizer}->Add($self->{Label_time}, 0, wxEXPAND | wxALL, 1);
	$self->{Sizer}->Add($self->{Label_m}, 1, wxEXPAND | wxALL, 1);
	$self->{Sizer}->Add($self->{Label_s}, 1, wxEXPAND | wxALL, 1);
	$self->{Sizer}->Add($self->{Label_c}, 1, wxEXPAND | wxALL, 1);
	$self->SetSizer($self->{Sizer});
	return $self;
}

sub setEmpire
{
	my $self = shift;
	my $empire = shift;
	return unless $empire->getProp('player_name');
	$self->{Label_player}->SetLabel($empire->getProp('player_id').': '.$empire->getProp('player_name'));
	$self->{Label_turn}->SetLabel($empire->getProp('turn'));
	$self->{Label_time}->SetLabel($empire->getProp('time_left'));
	my %colors = (
		'o' => Wx::Colour->new(0, 255, 0),
		'e' => Wx::Colour->new(0, 255, 255),
		'm' => Wx::Colour->new(255, 0, 0),
	);
	$self->{Label_m}->SetForegroundColour($colors{$empire->getProp('industry_nature')});
	$self->{Label_m}->SetLabel(
		int($empire->getProp('main_res')).' +'.
		$empire->getProp('main_per_turn').' -'.
		$empire->getProp('main_per_turn_spent').' ('.
		($empire->getProp('main_per_turn') - $empire->getProp('main_per_turn_spent')).')');
	$self->{Label_s}->SetForegroundColour($colors{$empire->getProp('unused_resource')});
	$self->{Label_s}->SetLabel(
		int($empire->getProp('second_res')).' +'.
		$empire->getProp('second_per_turn').' -'.
		$empire->getProp('second_per_turn_spent').' ('.
		($empire->getProp('second_per_turn') - $empire->getProp('second_per_turn_spent')).')');
	$self->{Label_c}->SetLabel(
		int($empire->getProp('money')).' +'.
		$empire->getProp('money_per_turn').' -'.
		$empire->getProp('money_per_turn_spent').' ('.
		($empire->getProp('money_per_turn') - $empire->getProp('money_per_turn_spent')).')');
}

1;
